package com.yunxin.admin.system.api.core.customer;

import com.yunxin.admin.system.infra.common.constant.SecurityConstants;
import com.yunxin.admin.system.infra.framework.security.util.SecurityUtils;
import com.yunxin.common.result.Result;
import com.yunxin.core.customer.dto.OperationCustomerChangeDto;
import com.yunxin.core.customer.service.CustomerChangeService;
import com.yunxin.core.customer.vo.CustomerChangeInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "14.流转客户")
@Slf4j
@RestController
@RequestMapping("/core/v1/customer/change")
@RequiredArgsConstructor
public class CustomerChangeController {

    @Autowired
    private CustomerChangeService customerChangeService;



    @Operation(summary = "流转客户", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
    @PostMapping("/customerChange")
    @PreAuthorize("@ss.hasPerm('boke:customerChange:create')")
    public Result<Boolean> customerChange(@Validated @RequestBody OperationCustomerChangeDto dto) {

        Long userId = SecurityUtils.X.getUser().getUserId();
        dto.setOperator(userId.intValue());
        return Result.success(customerChangeService.customerChange(dto));

    }

    @Operation(summary = "流转客户详情", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
    @GetMapping("/customerChangeInfo")
    @PreAuthorize("@ss.hasPerm('boke:customerChange:detail')")
    public Result<List<CustomerChangeInfoVo>> customerChangeInfo(@RequestParam("customerId") Integer customerId) {
        return Result.success(customerChangeService.customerChangeInfo(customerId));
    }


}
